package com.zqxq.lottery.service.user.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.zqxq.lottery.entity.po.user.UserFundsPO;
import com.zqxq.lottery.entity.po.user.UserInfoPO;
import com.zqxq.lottery.mapper.user.UserFundsMapper;
import com.zqxq.lottery.mapper.user.UserInfoMapper;
import com.zqxq.lottery.service.user.IUserAlipayService;
import com.zqxq.lottery.entity.po.user.UserAlipayPO;
import com.zqxq.lottery.mapper.user.UserAlipayMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
@Slf4j
public class UserAlipayServiceImpl extends ServiceImpl<UserAlipayMapper,UserAlipayPO> implements IUserAlipayService {

    @Autowired
    private UserFundsMapper userFundsMapper;
    @Autowired
    private UserInfoMapper userInfoMapper;

    @Override
    public void bindAlipay(long userId, String alipayAccount, String openId, UserInfoPO userInfoPO) {

        UserAlipayPO alipayPO = new UserAlipayPO();
        alipayPO.setUser_id(userId);
        alipayPO.setAlipay_account(alipayAccount);
        alipayPO.setAlipay_key(openId);
        alipayPO.setId(userId);

        insertOrUpdate(alipayPO);
        //修改是否绑定

        UserFundsPO userFundsPO = new UserFundsPO();
        userFundsPO.setUser_id(userId);
        userFundsPO.setAlipay_bind(1);
        userFundsMapper.updateById(userFundsPO);

        userInfoMapper.updateById(userInfoPO);
    }
}
